<!DOCTYPE html>
<html lang="en">

<head>
    <script src="../utils/flexible.js"></script>
    <script src="../utils/template.js"></script>
    <link rel="stylesheet" href="../assets/iconFonts/iconfont.css">
    <link rel="stylesheet" href="../css/inlanddiscount.css">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>inlanddiscount</title>
    <script src="../js/backtop.js"></script>
    <script src="../utils/jquery3.6.js"></script>
</head>

<body>
    <div class="header">
        <a href="../index.html">
            <</a> <h4>国内折扣</h4>
                <div>
                    <a href="">
                        <img src="../assets/images/header_app.png" alt="">
                    </a>
                </div>
    </div>
    <div class="main">
        <ul class="info clear">

        </ul>
    </div>
    <section class="footer">
        <div class="footmore ">
            <a href="">更多优惠信息>>></a>
        </div>
        <div class="chart clear">
            <span>品牌排行</span>
            <span><img src="../assets/images/more.png" alt=""></span>
        </div>
        <div class="login">
            <div class="foottop">
                <div class="footrow clear">
                    <a href="../index.html">登入</a>
                    <a href="../index.html">注册</a>
                    <a href="">返回顶部</a>
                </div>
            </div>
            <div class="footbottom">
                <p>
                    <a href="">手机app下载</a>
                    <a href="">慢慢买手机版</a>
                    -- 掌上比价平台
                </p>
                <p>m.manmanbuy.com</p>
            </div>
        </div>
    </section>
</body>

</html>
<script>
    $(function () {
        let num = 4
        //渲染函数(发送请求+数据处理渲染)
        function render(obj) {
            let r = {
                callfn: function () {}
            }
            for (let k in obj) {
                r[k] = obj[k]
            }
            $.ajax({
                url: 'http://chst.vip:1234/api/getinlanddiscount',
                success(res) {
                    r.callfn(res)
                }
            })
        }
        render({
            callfn: function (data) {
                callback(data)
            }
        })
        //数据处理函数
        function callback(res) {
            let objdata = {}
            let arrdata = []
            let data1 = res.result.slice(0, num)
            for (let i = 0; i < data1.length; i++) {
                arrdata.push(data1[i])
            }
            objdata.result = arrdata
            let html = template('li', objdata)
            $('.info').html(html)
        }
       
        backtop()

    })
</script>
<script type="text/html" id="li">
    {{each result as value i}}
    <li class="clear fl">
        <a href="inlanddiscount.html?productid={{value.productId}}&title=国内折扣" class="clear">
            <div class="img">{{@value.productImg}}</div>
            <div class="title">{{value.productName}}</div>
            <p class="price">{{value.productPrice}}</p>
            <p class="from">{{value.productFrom}}|{{value.productTime}}</p>
        </a>
    </li>
    {{/each}}
</script>